﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace EcSalseManage.EcSalse
{
    public partial class Project_Search : System.Web.UI.Page
    {
        DataAccess.Operate.DA_Project_Department_Inherit Project_Department_Inherit = new DataAccess.Operate.DA_Project_Department_Inherit();
        DataAccess.Operate.DA_Project_Present_Inherit Project_Present_Inherit = new DataAccess.Operate.DA_Project_Present_Inherit();
        DataAccess.Operate.DA_Project_SignType_Inherit Project_SignType_Inherit = new DataAccess.Operate.DA_Project_SignType_Inherit();
        DataAccess.Operate.DA_Project_ProductType_Inherit Project_ProductType_Inherit = new DataAccess.Operate.DA_Project_ProductType_Inherit();
        DataAccess.Operate.DA_Project_AgencyType_Inherit Project_AgencyType_Inherit = new DataAccess.Operate.DA_Project_AgencyType_Inherit();
        DataAccess.Operate.DA_Project_Province_Inherit Project_Province_Inherit = new DataAccess.Operate.DA_Project_Province_Inherit();
        DataAccess.Operate.DA_Project_Operate Project_Operate = new DataAccess.Operate.DA_Project_Operate();
        DataAccess.Operate.DA_Project_Search_Inherit Project_Search_Inherit = new DataAccess.Operate.DA_Project_Search_Inherit();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                DataSet ds = new DataSet();

                this.btnSearch.Attributes.Add("OnClick", "return DataCheck();");

                ds = Project_Department_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlDepartment, ds.Tables[0], "Project_Deparement_ID", "Project_Deparement_Name", "", "--请选择所属部门--");

                ds = Project_SignType_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlSignType, ds.Tables[0], "Project_SignType_ID", "Project_SignType_Name", "", "--请选择签署类型--");
                
                ds = Project_Present_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlProjectState, ds.Tables[0], "Project_Present_ID", "Project_Present_Name", "", "--请选择项目现况--");

                //wsKDHR.Service wsKDHRMS = new wsKDHR.Service();
                //ds = wsKDHRMS.HRDepartmentList();
                //Common.Common_Function.DropDownListBind(ddlHRDepartmentList, ds.Tables[0], "ID", "Name", "", "--请选择--");

                //ds = Project_ProductType_Inherit.FindLibraryAll();
                //CheckBoxNew(chklProductType, ds.Tables[0]);

                //ds = Project_AgencyType_Inherit.FindLibraryAll();
                //CheckBoxNew(chklAgencyType, ds.Tables[0]);

                ds = Project_Province_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlDeveloperProvince, ds.Tables[0], "Province_ID", "Province_Name", "", "--请选择项目现况--");

                this.ddlDeveloperProvince.Attributes.Add("onchange", "FillCity(this,document.form1.ddlDeveloperCity);");
                this.ddlDeveloperCity.Attributes.Add("onchange", "FillDistrict(this,document.form1.ddlDeveloperDistrict);");
            }
        }

        public void CheckBoxNew(CheckBoxList chkl, DataTable tb)
        {
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                ListItem item = new ListItem(tb.Rows[i][1].ToString(), tb.Rows[i][0].ToString());
                item.Attributes.Add("onclick", "chklAgencyType(this);");
                chkl.Items.Add(item);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGuid();
        }

        private void BindGuid()
        {
           
            DataTable dtResult;

            dtResult = Project_Search_Inherit.getResult(txtProjectName.Text, ddlSignType.SelectedValue.ToString(), txtSignDate.Text.Trim(), txtSignDateEnd.Text.Trim(), txtDeveloper.Text, ddlDeveloperProvince.SelectedValue.ToString(), ddlDeveloperCity.SelectedValue.ToString(), ddlDeveloperDistrict.SelectedValue.ToString(), txtDeveloperAddress.Text, ddlProjectState.SelectedValue.ToString(), "", "", "", Session["Building"]==null?"":Session["Building"].ToString());
            
            GridView1.DataSource = dtResult;
           
            GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string Project_PresentID = e.Row.Cells[4].Text;
                e.Row.Cells[4].Text = Project_Present_Inherit.FindLibrary(Project_PresentID).Tables[0].Rows[0][1].ToString();
                string Project_DepartmentID = e.Row.Cells[6].Text;
                e.Row.Cells[6].Text = Project_Department_Inherit.FindLibrary(Project_DepartmentID).Tables[0].Rows[0][1].ToString();


                e.Row.Cells[8].Attributes.Add("onClick", @"window.open('Project_Detail.aspx?ProjectID=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "&iType=2&openType=1&AuditType=','','height=1069,width=1057,menubar=no,toolbar=no,location=no,directoris=no,status=yes,resizable=no,scrollbars=yes','fullscreen');");
                e.Row.Cells[9].Attributes.Add("onClick", @"window.open('Report_Manager.aspx?ProjectID=" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "&iType=2&openType=1&AuditType=','','width=1024,menubar=no,toolbar=no,location=no,directoris=no,status=yes,resizable=yes,scrollbars=yes','fullscreen');");
            }
        }


   
    }
}
